<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
<title>批量导入数据</title>
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
 <script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script>  
<style type="text/css">
html,body {
	font-size: 12px;
	padding: 0;
	margin: 0;
	border: 0;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body onload="makePC()">
<fieldset style="border:solid 1px #aaa;padding:3px;">
<legend >单位制卡批量登记</legend> 
  <form id="form1"  enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath}/make.do?method=exkcdate">
    <div style="padding-left:11px;padding-bottom:5px;text-align:center">
  <table style="table-layout:fixed">
   <tr>
      <td style="white-space:nowrap;width:90px ;text-align:right" >劳动保障证号:</td>
      <td style="width:180px"><input class="mini-textbox" name="aab001" style="width:100%" id="key" onenter="onKeyEnter" required="true" vtype="int;minLength:8" maxlength="8" emptyText="请输入劳动保障证号"/></td>      
      <td style="width:90px ;text-align:right ">制卡批次:</td>
      <td style="width:180px"><input name="aaz001" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false"  style="width:100%"/></td>  
      <td style="width:90px ;text-align:right ">单位名称:</td>
      <td style="width:180px"><input  name="aab004" inputStyle="background:rgb(241,241,243)" class="mini-textbox" style="width:100%"  allowInput="false"/></td>    
    </tr>  
    <tr>
     <td style="width:90px ;text-align:right ">银 行:</td>
      <td style="width:180px"><input name="aae008" class="mini-combobox" required="true" style="width:100%"  textField="aaa103" valueField="aaa102" emptyText="请选择..."
      url="${pageContext.request.contextPath }/make.do?method=getyinhang&sj=bank"/></td>   
     <td style="width:90px ;text-align:right ">联系人:</td>
      <td style="width:180px"><input  name="aae004" class="mini-textbox" inputStyle="background:rgb(241,241,243)" style="width:100%" allowInput="false"/></td>
      <td style="width:90px ;text-align:right ">联系电话:</td>
      <td style="width:180px"><input name="aae005"  class="mini-textbox" inputStyle="background:rgb(241,241,243)"  style="width:100%" allowInput="false"/>
      <input id="eventid" name="eventid" class="mini-hidden" style="width:100%" />
      </td>           
    </tr>  
     <tr>
    <td style="width:90px;text-align:right ">请选择文件:</td>
    <td style="width:540px " colspan="3">
    <input style="width:100%" type="file" name="file" id="file"  multiple="multiple"/>     
    </td>    
    </tr>       
    </table>
    </div>  
  </form>   
     <div style="text-align:center;padding:10px;">
      <a class="mini-button" id="check" onclick="check" iconCls="icon-download"  style="width:60px;margin-right:20px;">导入</a>
				<a class="mini-button" onclick="onOk" id="onoks" iconCls="icon-ok"  enabled="false"
					style="width:60px;margin-right:20px;">确定</a><a class="mini-button" id="exporter" enabled="false"
					iconCls="icon-upload" onclick="exporter"
					style="width:60px;margin-right:20px;">导出</a> <a class="mini-button"
					iconCls="icon-remove" onclick="onReset"
					style="width:60px;margin-right:20px;">重置</a>
			</div>

  </fieldset>
<div id="b" class="mini-fit"  >
<div id="datagrid2" class="mini-datagrid" showReloadButton="false" showPageInfo="false"
		style="width:100%; height:100%;"  allowResize="true" frozenStartColumn="0"  
		url="" idField="id" allowRowSelect="false" >
<div property="columns">
			<div type="indexcolumn" ></div>		
			<div field="c1" align="center" headerAlign="center" >社会保障卡号</div>
			<div field="c2"  align="center" headerAlign="center" >证件号</div>
			<div field="c3"  align="center" headerAlign="center" >姓名</div>
			<div field="c4" align="center" headerAlign="center" >所属一级机构</div>
			<div field="c5"  align="center" headerAlign="center" >所属二级机构</div>
			<div field="execmsg" align="center"  headerAlign="center" >错误信息</div>
 </div> 
</div>
</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid2");  
var form = new mini.Form("form1");
  function onKeyEnter()
        {
          var aab001 = mini.getbyName("aab001").getValue().trim();  
           if(aab001 == "")
          {
             mini.alert("请输入社会保障卡号");
             return;
          } else{                            
           $.ajax({               
                    url: "/sbk/make.do?method=getunitdata",
                    cache: false,
                    data:{id:aab001},
                    success: function (text) {  
                        if(text != "null") 
                        {               
                        var o = mini.decode(text);                      
                        mini.getbyName("aab004").setValue(o.aab004);
                        mini.getbyName("aae004").setValue(o.aae004); 
                        mini.getbyName("aae005").setValue(o.aae005);                       
                        labelModel();  
                         } 
                        else
                        {                         
                           mini.alert("无效劳动保障卡号");
                           return;
                        }                         
                    }
                });        
        }
        } 
      function makePC()
        {               
         $.ajax({               
                    url: "/sbk/make.do?method=getMakePc",                                     
                    success: function (text) { 
                    if(null == text || "null" == text || "" == text) 
                    {
                       mini.alert("无此制卡批次");
                       return;
                    }                                                  
                    mini.getbyName("aaz001").setValue(text);                                                                                                                                             
                    }
                });    
        
        }
         function check() {              
            var arrId=new Array(); 
            arrId[0] ="file" ;   
            var value = $("#file").attr("value");                   
            if(value == "" || value == null)
            {               
               mini.alert("请上传文件");
               return;            
            }  else {        
            $.ajaxFileUpload({
            url:"${pageContext.request.contextPath }/AZ20file.do?method=dofile",
            type : 'post',
            secureuri : false,
            fileElementId : arrId,
            dataType : 'text',
            success: function (text) {
            if("" == text || null == text || "null" == text)
            {
              mini.alert("上传失败");
            }
            else
            {
               mini.getbyName("eventid").setValue(text); 
               getdate();
               mini.get("check").setEnabled(false);
               mini.get("onoks").setEnabled(true);
               mini.get("exporter").setEnabled(true);
            }
                
           }          
            });
         }                      
     }
          function getdate()
          {
              var eventid = mini.getbyName("eventid").getValue().trim();             
              if(eventid.length>20) {
              eventid=eventid.substring(eventid.length-22,eventid.length-6);             
              }
              $.ajax({
				url : "/sbk/make.do?method=checkdate",
				type : 'post',
				data : {
					eventid : eventid
				},
				cache : false,
				success : function(text) {	
				if(null == text || "null" == text || "" == text)
				{
				   mini.alert("文件不符，上传失败");
				   return;
				}
				mini.alert(text);						                    
                grid.setUrl("/sbk/make.do?method=getunit&key="+ eventid);
                grid.load();    	        								
				},
				error : function(jqXHR, textStatus, errorThrown) {
					mini.alert(jqXHR.responseText);					
				}
			});
          
          }
         
          function onOk() {        					
			form.validate();					      	  	                               
            if (form.isValid() == false)
			{
			  return;
			}		 
			
			SaveData();   		                                                         
        }
        
          function exporter(){
             var eventid = mini.getbyName("eventid").getValue().trim();   
              if(eventid.length>20) {
              eventid=eventid.substring(eventid.length-22,eventid.length-6);  
               mini.getbyName("eventid").setValue(eventid);            
              }
		     if(eventid!=""){
		    var form = document.getElementById("form1");	
			form.submit();
		     } 
		     else
		    {
		       mini.alert("请导入文件");
		    }
          }   
             
         function SaveData() {
			var o = form.getData();				
			form.validate();
			if (form.isValid() == false)
			{
			   	return;	
			}					  	    	
			 if(form.isValid()==true){
      	  		mini.mask({el: document.body,cls: 'mini-mask-loading',html: '保存中...'});      	 	
			var json = mini.encode([o]);		
			$.ajax({
				url : "/sbk/make.do?method=saveunitpl",
				type : 'post',
				data : {
					data : json
				},
				cache : false,
				success : function(text) {	
				    mini.unmask();
				      if("0"== text)
				    {
				     mini.alert("登记成功");
				     mini.get("onoks").setEnabled(false); 
				     labelModel2();
				    }
				    else
				    {
				      mini.alert("登记失败:"+text);
				      mini.get("onoks").setEnabled(false); 				      
				    }						   												
				},
				error : function(jqXHR, textStatus, errorThrown) {
					mini.alert(jqXHR.responseText);					
				}
			});
}
		}	
		function labelModel() {
            var fields = form.getFields();                          
                var c = fields[0];
                if (c.setReadOnly) c.setReadOnly(true);     //只读
                if (c.setIsValid) c.setIsValid(true);      //去除错误提示
                if (c.addCls) c.addCls("asLabel");          //增加asLabel外观           
        }
        
        function labelModel2() {
            var fields = form.getFields();                          
                var c = fields[3];
                if (c.setReadOnly) c.setReadOnly(true);     //只读
                if (c.setIsValid) c.setIsValid(true);      //去除错误提示
                if (c.addCls) c.addCls("asLabel");          //增加asLabel外观           
        }
        
         function inputModel2() {
            var fields = form.getFields();           
                var c = fields[0];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");          
            mini.repaint(document.body);
        }
        
         function inputModel1() {
            var fields = form.getFields();           
                var c = fields[3];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");          
            mini.repaint(document.body);
        }
	
          function onReset(e) {
			form.clear();
			inputModel2();
			inputModel1();
			var file = document.getElementById("file");
            file.outerHTML=file.outerHTML.replace(/(value=\").+\"/i,"$1\""); 
            mini.get("exporter").setEnabled(false);
		    mini.get("onoks").setEnabled(false); 
		    mini.get("check").setEnabled(true);
		    grid.setUrl("/sbk/make.do?method=getunit&key");
            grid.load();  
			makePC();
		}
</script>
</body>
</html>





